using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Unity.VisualScripting;
using UnityEngine;
using XLua;

public class LuaGameManager : MonoBehaviour
{
    private LuaEnv lua;
    
    private Action _startAction;
    private Action _updateAction;
    
    // Start is called before the first frame update
    void Start()
    {
        lua = new LuaEnv();
        
        lua.AddLoader(OnAddLua);

        lua.DoString("require'GD_LUAScript'");

        _startAction = lua.Global.GetInPath<Action>("Gd_Start");
        
        _updateAction = lua.Global.GetInPath<Action>("Gd_UpDate");

        _startAction?.Invoke();
    }

    private byte[] OnAddLua(ref string filepath)
    {
        string path = Application.dataPath + "/LuaScripts/";

        string endPath = path + filepath + ".lua";

        return File.ReadAllBytes(endPath);
    }
    
    // Update is called once per frame
    void Update()
    {
        _updateAction?.Invoke();
    }
}
